﻿namespace TianYu.Core.Common
{
    public class TYBaseException : Exception
    {
        public string MsgCode { get; set; }
        public object[] Arguments { get; set; }
        public TYBaseException(string msgCode, params object[] arguments) : base(message: DefaultMessage(msgCode, arguments))
        {
            MsgCode = msgCode;
            Arguments = arguments;
        }
        public TYBaseException(string msgCode, Exception innerException, params object[] arguments) : base(DefaultMessage(msgCode, arguments), innerException)
        {
            MsgCode = msgCode;
            Arguments = arguments;
        }

        private static string DefaultMessage(string msgCode, params object[] arguments)
        {
            if (arguments == null || arguments.Length < 1) return msgCode;

            return $"{msgCode}:{string.Join(',', arguments)}";
        }
    }
}
